//
//  LeaveViewController.swift
//  BellManage
//
//  Created by Bestsch on 16/4/12.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class LeaveViewController: BaseViewController, UITableViewDelegate,UITableViewDataSource {
    
    var tableView: UITableView!
    
    var array = NSMutableArray()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        self.title = "今日请假"
        
        InitwViews()
    }
    
    func InitwViews()  {
        tableView = UITableView.init(frame: CGRect(x: 0, y: 0, width: screenW, height: screenH))
        tableView.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
        self.view.addSubview(tableView)
        setUpRefresh()
    }
    func setUpRefresh() {
        tableView.header = MJRefreshNormalHeader.init(refreshingTarget: self, refreshingAction: #selector(LeaveViewController.refresh))
        tableView.header.beginRefreshing()
    }
    func refresh() {
        
        if (reachability?.isReachable())! {
            let user = getUserPojo()
            let request = requestHeader + "19</t><sch>" + user.schid + "</sch></channel></rss>"
            let url = server + adminwebapppi
            
            array = getData(url, request: request)
            tableView.reloadData()
            
        } else {
            HYLog("网络连接：不可用")
        }

        tableView.header.endRefreshing()
        
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "ClassSendTableViewCellIdentifier";
        
        let cell: ClassSendTableViewCell = ClassSendTableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: cellIdentifier)
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        cell.selectionStyle = UITableViewCellSelectionStyle.none;
        let dic = array[indexPath.row] as! JSON
        let classname = dic["classname"].stringValue
        let count = dic["classcon"].stringValue
        
        cell.classname.text = classname
        cell.count.text = "请假人数：" + count
        
        return cell
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let dic = array[indexPath.row] as! JSON
        let classid = dic["classid"].stringValue
        let classname = dic["classname"].stringValue
        let leave = LeaveContentViewController()
        leave.classid = classid
        leave.className = classname
        self.navigationController?.pushViewController(leave, animated: true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
}
